<template>
	<view class="container">
		<uni-card :title="'用户:'+item.id+''" :extra="item.postDate" note="Tips"
			v-for="item,index in commentlist">
			评论：     {{item.comment}}
		</uni-card>
		<uni-load-more :status="'more'" @clickLoadMore="loadmore"
			:contentText="{contentdown:  '显示更多',contentrefresh: '正在加载...',contentnomore: '没有更多数据了'}"></uni-load-more>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageIndex: 1,
				pageSize: 5,
				foodid: 1,
				commentlist: [],
			}
		},
		onReachBottom() {
			uni.showLoading()
			setTimeout(()=>{
				this.loadmore()
			},1000);
		},
		methods: {
			reload(){
				uni.request({
					url: 'http://localhost:8090/foodapp/comments/getCommentsByFoodIdByPage',
					method: 'POST',
					header: {
						'content-type': 'application/json'
					},
					data: {
						foodid: this.foodid || 1,
						pageIndex: 1,
						pageSize: this.pageSize
					},
					success: res => {
						this.commentlist = res.data.data.content
						console.log(this.commentlist);
				
					},
					fail: (err) => {
						console.log(err);
					},
					complete: () => {
						uni.stopPullDownRefresh()
					}
				});
			},
			loadmore() {
				
				this.pageIndex = this.pageIndex +1
				uni.request({
					url: 'http://localhost:8090/foodapp/comments/getCommentsByFoodIdByPage',
					method: 'POST',
					header: {
						'content-type': 'application/json'
					},
					data: {
						foodid: this.foodid || 1,
						pageIndex: this.pageIndex,
						pageSize: this.pageSize
					},
					success: res => {
						this.commentlist = this.commentlist.concat(res.data.data.content)
						console.log(this.commentlist);

					},
					fail: (err) => {
						console.log(err);
					},
					complete: () => {
						uni.hideLoading()
					}
				});
			}
		},
		onPullDownRefresh() {
			this.reload()
		},
		onLoad(e) {
			console.log(e);
			this.foodid = e.foodid
			this.reload()
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
